package cn;

import java.util.Arrays;
import java.util.Random;

public class Alphabet {
	char[] change(int[] arr) {
		char[] cs = new char[arr.length];
		for(int i = 0; i < arr.length; i ++) {
			cs[i] = (char)arr[i];
		}
		return cs;
	}
	
	void input() {
		Random rnd = new Random();
		// 随机取出24个字母
		int[] a = new int[24];
		System.out.println("随机取出24个不相同的字母");
		for (int i = 0; i < a.length; i++) {
			a[i] = rnd.nextInt(26) + 65;
			for (int j = 0; j < i; j++) {
				if (a[i] == a[j]) {
					i--;
				}
			}
		}
		System.out.println(Arrays.toString(a));

		// 随机分配四个人：
		int[] arr1 = new int[6];
		int[] arr2 = new int[6];
		int[] arr3 = new int[6];
		int[] arr4 = new int[6];
		for (int i = 0; i < arr1.length; i++) {
			arr1[i] = a[i];
			arr2[i] = a[i + 6];
			arr3[i] = a[i + 12];
			arr4[i] = a[i + 18];
		}
		System.out.println("输出各数组：");
		System.out.println(Arrays.toString(arr1));
		System.out.println(Arrays.toString(arr2));
		System.out.println(Arrays.toString(arr3));
		System.out.println(Arrays.toString(arr4));
		System.out.println();
		// 将各数组排序
		for (int i = 0; i < 5; i++) {
			for (int j = 0; j < 6 - i - 1; j++) {
				if (arr1[j] > arr1[j + 1]) {
					int temp = arr1[j + 1];
					arr1[j + 1] = arr1[j];
					arr1[j] = temp;
				}
				if (arr2[j] > arr2[j + 1]) {
					int p = arr2[j + 1];
					arr2[j + 1] = arr2[j];
					arr2[j] = p;
				}
				if (arr3[j] > arr3[j + 1]) {
					int e = arr3[j + 1];
					arr3[j + 1] = arr3[j];
					arr3[j] = e;
				}
				if (arr4[j] > arr4[j + 1]) {
					int m = arr4[j + 1];
					arr4[j + 1] = arr4[j];
					arr4[j] = m;
				}

			}
		}
		System.out.println("输出排序后的数组：");
		
		/*void output(int[] arr){
		for(int i = 0;i < 4;i++)
			for(int j = 1;j < 6;j++) {
				System.out.printf("%c",arr[j]);
			}
		}*/
	
		System.out.println(Arrays.toString(change(arr1)));
		System.out.println(Arrays.toString(change(arr2)));
		System.out.println(Arrays.toString(change(arr3)));
		System.out.println(Arrays.toString(change(arr4)));
	}
	
	public static void main(String[] args) {
		Alphabet a = new Alphabet();
		a.input();

	}

}
